<?php

namespace app\admin\model;

use think\Model;

class WalletLog extends Model {

    // 表名
    protected $name = 'wallet_log';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'change_type_text',
        'change_matters_text',
    ];

    public function getChangeTypeList() {
        return ['0' => '收入', '1' => '支出'];
    }

    public function getChangeMattersList() {
        return ['1' => '充值', '2' => '充值赠送', '3' => '平台调整', '4' => '购物', '5' => '补货'];
    }

    public function getChangeMattersTextAttr($value, $data) {
        $value = $value ? $value : $data['change_matters'];
        $list = $this->getChangeMattersList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getChangeTypeTextAttr($value, $data) {
        $value = $value ? $value : $data['change_type'];
        $list = $this->getChangeTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

}
